package org.csu.mypetstore.web.servlet;

import org.csu.mypetstore.domain.Item;
import org.csu.mypetstore.service.CatalogService;

import javax.servlet.*;
import javax.servlet.http.*;
import javax.servlet.annotation.*;
import java.io.IOException;

@WebServlet(name = "ItemServlet", value = "/ItemServlet")
public class ViewItemServlet extends HttpServlet {
    private static final String VIEW_ITEM="/WEB-INF/jsp/catalog/Item.jsp";
    private String itemId;


    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        itemId=request.getParameter("itemId");
        CatalogService service=new CatalogService();
        Item item = service.getItem(itemId);
        HttpSession session=request.getSession();
        session.setAttribute("item",item);
        request.getRequestDispatcher(VIEW_ITEM).forward(request,response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        doGet(request, response);

    }
}
